<!
 ============================================================================
 Name        : index.php
 Author      : Stefan Nagel
 Version     : 0.0.2
 Copyright   : 2014 Stefan Nagel
 	 	 	 	This file is part of the BringYourOwnDevice application.
				BringYourOwnDevice is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
				BringYourOwnDevice is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
				You should have received a copy of the GNU General Public License along with zeitmessanlage. If not, see http://www.gnu.org/licenses/.
  Description : Main code for the webpage
 ============================================================================
 >

<html>
<body>



<?php
if( isset( $_POST["Upload"] ) )
{
    $target_path = "upload/";
    $target_path = $target_path . basename( $_FILES['filename']['name']); 

    if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path))
	{
        echo "The file ".  basename( $_FILES['filename']['name']). " has been uploaded";
    }
	else
	{
        echo "There was an error uploading the file, please try again!";
    }
}

if( isset( $_POST["QR-Code"] ) )
{
	
	//set it to writable location, a place for temp generated PNG files
    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
    
    //html PNG location prefix
    $PNG_WEB_DIR = 'temp/';

    include "php/phpqrcode/qrlib.php";    
    
    //ofcourse we need rights to create temp dir
    if (!file_exists($PNG_TEMP_DIR))
        mkdir($PNG_TEMP_DIR);
	$filename = $PNG_TEMP_DIR.'test.png';
	$matrixPointSize = 5;
	$errorCorrectionLevel = 'L';
	
	QRcode::png("http://192.168.42.10/Schule/".basename( $_FILES['filename']['name']), $filename, $errorCorrectionLevel, $matrixPointSize, 2);
	//display generated file
	if(basename( $_FILES['filename']['name']))
	{
		echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; 
    }
	else
	{
        echo "Please choose a valid file!";
    }
     
}


?>
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <input type="file" name="filename" />
    <input type="submit" value="Upload" name="Upload" />
    <input type="submit" value="QR-Code" name="QR-Code" />
</form>

</body>
</html> 